<template>
  <div class="sydjzx con-layout">
    <my-bread title="注销信息" :goback="true"></my-bread>
    <div class="sydjzx-content">
      <co-form :model="data" :rules="rules" ref="form">
        <co-input label="失业登记日期：" v-model="sydjrq" :disabled="true"></co-input>
        <co-select prop="zxyy" label="失业登记注销原因：" v-model="data.zxyy" :list="zxyyList"></co-select>
        <div v-if="data.zxyy == '0070'">
          <co-input prop="cjsbh" label="裁决书编号：" v-model="data.cjsbh"></co-input>
          <data-picker prop="cjsrq" label="裁决日期：" v-model="data.cjsrq"></data-picker>
          <co-textarea prop="cjsnr" label="裁决书内容：" v-model="data.cjsnr"></co-textarea>
        </div>
      </co-form>
      <div class="next-step">
        <span class="btn btn-light" @click="cancel">返回</span>
        <span class="btn btn-primary" @click="save">保存</span>
      </div>
    </div>
  </div>
</template>

<script>
import coForm from "base/form/form";
import coInput from "base/form/input";
import coTextarea from "base/form/textarea/textarea";
import coSelect from "base/form/select";
import dataPicker from "base/form/dataPicker3";
import { validator } from "common/js/valid";
import { sessionStorageSetItem, sessionStorageGetItem } from "common/js/utils";

export default {
  name: "sydjzx",
  components: { coForm, coInput, coSelect, coTextarea, dataPicker },
  data() {
    return {
      data: {
        zxyy: "", //失业登记注销原因
        cjsbh: "", //裁决书编号
        cjsrq: "", //裁决日期
        cjsnr: "" //裁决书内容
      },
      rules: {
        zxyy: validator("10,full,失业登记注销原因,false"),
        cjsbh: validator("50,full,裁决书编号,false"),
        cjsrq: validator("10,full,裁决日期,false"),
        cjsnr: validator("100,full,裁决书内容,false")
      },
      zxyyList: [], //注销原因代码表
      syzxObj: sessionStorageGetItem("syzxObj") //失业登记用到的参数
    };
  },
  watch: {
    "data.zxyy"(n) {
      if (n != "0070") {
        this.data.cjsbh = "";
        this.data.cjsrq = "";
        this.data.cjsnr = "";
      }
    }
  },
  computed: {
    sydjrq() {
      //失业登记日期
      let sydjrq = this.syzxObj.sydjrq;
      return (
        sydjrq.substring(0, 4) +
        "年" +
        sydjrq.substring(4, 6) +
        "月" +
        sydjrq.substring(6, 8) +
        "日"
      );
    }
  },
  created() {
    this.getDmb();
  },
  methods: {
    save() {
      this.$refs.form.validate(() => {
        this.data.grbh = this.syzxObj.grbh; //个人编号
        this.data.sydjid = this.syzxObj.sydjid; //失业登记id
        this.data.sydjrq = this.syzxObj.sydjrq; //失业登记日期
        this.data.sjly = "3";//微信端保存必填
        this.$confirm("确定要注销信息吗？", "提示").then(() => {
          this.$loading = true;
          this.$http
            .post("/jysydj/sydjzx/sydjzxSave", this.data)
            .finally(() => {
              this.$loading = false;
            })
            .then(res => {
              let _res = res.returnData;
              if (+_res.executeResult == 1) {
                this.$alert({
                  message: res.returnMsg,
                  cb:()=>{
                    this.$router.push({path:'/index'});
                  }
                });
              } else {
                this.$alert({
                  message: _res.message
                });
                return false;
              }
            });
        });
      });
    },
    cancel(){
      this.$router.goBack();
    },
    // 失业登记注销原因代码表
    getDmb() {
      this.$http
        .get("/jysydj/CodeOperation/getCodeData", {
          params: {
            dmbm: "syry_d_sydjzxyy"
          }
        })
        .then(res => {
          let _res = res.returnData;
          let _data = _res.syry_d_sydjzxyy;
          // if(this.syzxObj.hjxzqh.substring(0, 2) != '11'){
          //   _data.forEach(element => {
          //     if(element.id == '0035'){
          //       element.disabled = true;
          //     }
          //   });
          // }
          this.zxyyList = _data;
        });
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .form .weui-cells .form_wrap {
  background-color: #ffffff !important;
}
/deep/ .weui-cell .weui-cell__hd .weui-label {
  width: 300px;
}
.next-step {
  margin: 42px 0 20px 0;
  padding: 0 34px;
  .btn {
    width: 330px;
  }
  .btn-primary {
    margin-left: 10px;
  }
}
</style>
